home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / WList / WList.c < prev    next >
Encoding:
Text File  |  1993-08-14  |  2.6 KB  |  92 lines  |  [TEXT/KAHL]

  1. //
  2. //    WList.c, source code for the WList dcmd
  3. //
  4. //    Daniel Jibouleau, 25/7/94
  5. //
  6.  
  7. #include "dcmd.h"  // necessary to use 'dcmdGlue.c'
  8.  
  9. /* Prototypes */
  10. void AppendNum2Hex (Str255 dest, long number, short n);
  11. void AppendString (Str255 dest, Str255 source);
  12.  
  13. //
  14. //    Entry point: must be labelled 'CommandEntry'
  15. //
  16.  
  17. pascal void CommandEntry (dcmdBlock *pb)
  18. {
  19.     switch (pb -> request) {
  20.         case dcmdInit:
  21.             /* Nothing to do at init */
  22.             break;
  23.         case dcmdHelp:
  24.             /* Print out help text */
  25.             dcmdDrawLine ("\pWList");
  26.             dcmdDrawLine ("\p   Shows the list of all windows in the current application.");
  27.             break;
  28.         case dcmdDoIt: {
  29.             /* Do it: show all windows */
  30.             WindowPeek w = WindowList;                  // window to display info about: first window
  31.             Str255 s;  // string to print
  32.             
  33.             /* Print header */
  34.             dcmdDrawLine ("\p Address  Title                Kind Visible Hilite defProc  refCon");
  35.             
  36.             while (w) {  // loop
  37.                 Length (s) = 0;                           // start with an empty string
  38.                 AppendNum2Hex (s, (long) w, 8);           // append window address
  39.                 s [++ Length (s)] = ' ';                  // append a space
  40.                 
  41.                 AppendString (s, *w -> titleHandle);      // append window title
  42.                 while (Length (s) < 30)
  43.                     s [++ Length (s)] = ' ';                // ajust columns
  44.                 
  45.                 if (w -> windowKind == userKind)          // window
  46.                     AppendString (s, "\pwind ");
  47.                 else if (w -> windowKind == dialogKind)   // dialog box
  48.                     AppendString (s, "\pdlog ");
  49.                 else {                                    // other: print windowKind
  50.                     AppendNum2Hex (s, w -> windowKind, 4);  // append 
  51.                     s [++ Length (s)] = ' '; }
  52.                 
  53.                 AppendString (s, (w -> visible) ? "\ptrue    " : "\pfalse   ");  // visible
  54.                 AppendString (s, (w -> hilited) ? "\ptrue   "  : "\pfalse  ");   // hilited
  55.                 
  56.                 AppendNum2Hex (s, (long) w -> windowDefProc, 8);  // defProc
  57.                 s [++ Length (s)] = ' ';
  58.                 AppendNum2Hex (s, w -> refCon, 8);                // refCon
  59.                 s [++ Length (s)] = ' ';
  60.                 
  61.                 dcmdDrawLine (s);
  62.                 w = w -> nextWindow; }
  63.             break; }
  64.         }
  65. }
  66.  
  67. //
  68. //    AppendNum2Hex: appends an hex number to string 's'.  n specifies byte length (ex.: short=2, long=4)
  69. //
  70.  
  71. void AppendNum2Hex (Str255 s, long number, short n)
  72. {
  73.     short i;
  74.     
  75.     for (i = n; i >= 1; i --) {
  76.         s [Length (s) + i] = "0123456789ABCDEF" [number % 16];
  77.         number /= 16; }
  78.     
  79.     Length (s) += n;
  80. }
  81.  
  82. //
  83. //    AppendString: appends 'source' to the end of 'dest' string
  84. //
  85.  
  86. void AppendString (Str255 dest, Str255 source)
  87. {
  88.     BlockMove (source + 1, dest + 1 + Length (dest), Length (source));
  89.     Length (dest) += Length (source);
  90. }
  91.  
  92.